local cuixue = fk.CreateSkill{
  name = "rfenghou_3d15j__cuixue",
  tags = { Skill.Compulsory }
}

cuixue:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@rfenghou_3d15j__cuixue-turn", 0)
end)

cuixue:addEffect(fk.TurnStart, {
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(cuixue.name) or target ~= player then return false end
    if event == fk.TurnStart then
      return true
    else
      local cards = player:getCardIds("h")
      return #cards > 0 and table.every(cards, function(id) return Fk:getCardById(id).trueName == "slash" end)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = {"0", "1", "2"}
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = cuixue.name,
      prompt = "#rfenghou_3d15j__cuixue-choice"
    })
    room:setPlayerMark(player, "@rfenghou_3d15j__cuixue-turn", tostring(choice))
  end,
})

cuixue:addEffect(fk.TurnEnd, {
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(cuixue.name) or target ~= player then return false end
    local cards = player:getCardIds("h")
    return #cards > 0 and table.every(cards, function(id) return Fk:getCardById(id).trueName == "slash" end)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:showCards(player:getCardIds("h"))
    local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
    if #targets == 0 then return false end
    local tos = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#rfenghou_3d15j__cuixue-damage",
      skill_name = cuixue.name,
      cancelable = false
    })
    if #tos > 0 then
      room:damage {
        from = player,
        to = tos[1],
        damage = 1,
        skillName = cuixue.name
      }
    end
  end
})

cuixue:addEffect("maxcards", {
  correct_func = function(self, player)
    local mark = tonumber(player:getMark("@rfenghou_3d15j__cuixue-turn"))
    if mark ~= 0 then
      return - mark
    end
  end
})

cuixue:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
    return data.card.trueName == "slash" and player:getMark("@rfenghou_3d15j__cuixue-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + tonumber(player:getMark("@rfenghou_3d15j__cuixue-turn") - 1)
  end,
})

Fk:loadTranslationTable{
  ["rfenghou_3d15j__cuixue"] = "淬血",
  [":rfenghou_3d15j__cuixue"] = "锁定技，回合开始时，你令你本回合【杀】伤害基数和<a href=':rfenghou_discard_skill'>占用手牌上限</a>改为(0-2)，手牌上限减等量；回合结束时，你展示均为【杀】的手牌并对一名其他角色造成1点伤害。",

  ["@rfenghou_3d15j__cuixue-turn"] = "淬血",

  ["#rfenghou_3d15j__cuixue-damage"] = "淬血：对一名其他角色造成1点伤害",
  ["#rfenghou_3d15j__cuixue-choice"] = "淬血：请令本回合【杀】伤害基数和占用手牌上限改为上述一个数字！",

  ["$rfenghou_3d15j__cuixue1"] = "血债血偿、天理昭然！",
  ["$rfenghou_3d15j__cuixue2"] = "染刃尽是心头血，夙寐都作鬓间霜。",
}

return cuixue
